package com.wulang.extension.listener;


import com.rabbitmq.client.Channel;
import com.wulang.extension.constants.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

@Component
public class DLXListener {
//    @RabbitListener(queues = Constants.NORMAL_QUEUE)
//    public void dxlListener(Message message, Channel channel) throws IOException {
//        try {
//            System.out.printf("接收到的消息: %s\n", message);
//            int i = 3 / 0;//模拟异常情况
//            System.out.println("消息处理成功");
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            System.out.println("消息处理失败");
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//        }
//
//    }
    @RabbitListener(queues = Constants.DLQ_QUEUE)
    public void dlqListener(Message message, Channel channel) {
        //这里是消费者逻辑
        System.out.printf("%tc 接收到消息: %s, deliveryTag: %d \n", new Date(), new String(message.getBody()), message.getMessageProperties().getDeliveryTag());
    }

}
